package com.jiangjiang.eshop.finance.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.finance.convert.PurchaseSettlementOrderItemConvert;
import com.jiangjiang.eshop.finance.dao.PurchaseSettlementOrderItemMapper;
import com.jiangjiang.eshop.finance.domain.PurchaseSettlementOrderItem;
import com.jiangjiang.eshop.finance.dto.PurchaseSettlementOrderItemDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName PurchaseSettlementOrderItemService
 * @Description TODO
 * @Author jhw
 * @Date 2021/9/15 23:57
 * @Version 1.0
 **/
@Service
public class PurchaseSettlementOrderItemService extends ServiceImpl<PurchaseSettlementOrderItemMapper, PurchaseSettlementOrderItem> {
    @Autowired
    private PurchaseSettlementOrderItemConvert purchaseSettlementOrderItemConvert;


    /**
     * 采购结算单明细数据批量保存
     *
     * @param items 采购
     */
    public void saveBatchItems(List<PurchaseSettlementOrderItemDTO> items) {
        this.saveBatch(purchaseSettlementOrderItemConvert.convertDTOList2Entities(items));
    }

    /**
     * 采购结算单明细数据批量编辑
     * @param items
     */
    public void updateBatchItems(List<PurchaseSettlementOrderItemDTO> items) {
        this.updateBatchById(purchaseSettlementOrderItemConvert.convertDTOList2Entities(items));
    }

    /**
     * 根据采购结算单id查询明细数据
     *
     * @param purchaseSettlementOrderId 采购结算单id
     * @return 查询结果
     */
    public List<PurchaseSettlementOrderItemDTO> queryByPurchaseSettlementOrderId(Long purchaseSettlementOrderId) {
        LambdaQueryWrapper<PurchaseSettlementOrderItem> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(PurchaseSettlementOrderItem::getPurchaseSettlementOrderId, purchaseSettlementOrderId);
        return purchaseSettlementOrderItemConvert.convetEntities2DTOList(this.list(wrapper));
    }


}
